package com.ktjy.controller;

import com.ktjy.service.IUploadService;
import com.ktjy.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/file")
@Slf4j
public class UploadController {
    @Autowired
    IUploadService uploadService;

    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file){
        try {
            String fileName = uploadService.upload(file);
            return AjaxResult.success("文件上传成功",fileName);
        } catch (Exception e) {
            log.error("UploadController中upload方法执行报错的。",e);
        }
        return AjaxResult.error("文件上传失败");
    }

}
